<title>请示填报</title>
<script src="/src/lib/echarts.min.js"></script>
<div class="layui-card layadmin-header">
	<div class="layui-breadcrumb" lay-filter="breadcrumb" lay-separator=">">
        <a lay-href=""><i class="layui-icon layui-icon-locate"></i>您当前的位置：</a>
		<a><cite class="first-breadcrumb">填报管理</cite></a>
        <a><cite class="second-breadcrumb">填报请示</cite></a>
        <a><cite class="third-breadcrumb"></cite></a>
	</div>
</div>
<style>
    .top-part{
        margin: 12px 0 20px 0;
    }
    .left-card, .right-card, .layui-card{
        border-radius: 4px;
    }
    .right-card{
        height: 425px;
        background: #fff;
    }
    .scroll{
        overflow-y: scroll;
    }
    .task-ul{
        height: 345px;
        padding: 18px 0;
    }
    .task-ul ul{
        height: 100%;
        font-size: 14px;
    }
    .task-ul ul li{
        height: 32px;
        line-height: 32px;
        padding: 0 25px 0 20px;
        cursor: default;
    }
    .task-ul ul li+li:hover{
        background: #DCE7F4;
    }
    .layui-table td[data-field="6"]{
        text-align: left;
    }
    .filling{
        display: inline-block;
        width: 72px;
        height: 18px;
        line-height: 20px;
        font-size: 12px;
        background-color: #53C553;
        border-radius: 9px;
        color: #FEFFFE;
    }
    .addLine, .delLine{
        width: 24px;
        height: 22px;
        border: none;
        background-position: center center;
        background-repeat: no-repeat;
        margin-top: 4px;
        cursor: pointer;
    }
    .addLine{
        background: url(../../../../dist/style/res/formFill/add.png);
        margin-right: 40px;
    }
    .delLine{
        background: url(../../../../dist/style/res/formFill/del.png);
    }

    .left-card{
        margin-bottom: 0;
    }
    .layui-card-header{
        height: 19px;
        line-height: normal;
        padding: 10px;
        background-color: #F6F7F8;
    }
    .layui-card-body{
        padding: 0;
    }
    .card-header-icon{
        width: 18px;
        height: 18px;
    }
    .card-header-title{
        margin-left: 5px;
    }
    .layui-table-view .layui-table th, .layui-table-view .layui-table td{
        width: 286px;
        padding: 4px 0;
        text-align: center;
        vertical-align: middle;
    }
    .layui-tab-content .layui-table th{
        border: 1px solid #e6e6ee;
    }
    .btn-submit, .btn-forward, .btn-assign, .btn-return{
        height: 22px;
        font-size: 12px;
        border-radius: 4px;
    }
    .btn-submit{
        width: 48px;
        border: 1px solid #4BAA0B;
        color: #4BAA0B;
    }
    .btn-forward{
        width: 48px;
        border: 1px solid #1C74D4;
        color: #1C74D4;
    }
    .btn-assign{
        width: 60px;
        border: 1px solid #0078FF;
        color: #0078FF;
    }
    .btn-return{
        width: 62px;
        border: 1px solid #828282;
        color: #828282;
    }
    .layui-fluid{
        padding: 0 15px;
    }

    .undo-task{
        padding-left: 10px;
    }
    .task-content-box{
        float: left;
        width: 70%;
        height: 32px;
        text-overflow: ellipsis;
        overflow: hidden;
    }
    .task-num{
        display: inline-block;
        width: 25px;
        color: #373737;
    }
    .task-content{
        color: #373737;
    }
    .task-time{
        float: right;
        width: 30%;
        height: 32px;
        color:#666666;
        overflow: hidden;
        text-align: right;
    }
    .select-form-header{
        position: relative;
    }
    .card-header-right{
        position: absolute;
        right: 0;
        top: 0;
    }
    .layui-card .layui-tab{
        margin-top: 13px;
        z-index: 9999;
    }
    .layui-tab-card>.layui-tab-title{
        background: #fff;
    }
    .layui-tab-card{
        border-top: none;
    }
    .select-form-box{
        min-height: 400px;
    }
    .layui-tab-content{
        padding: 15px 9px;
    }
    .layui-table tbody tr.bgRed{
        background: red;
    }
    .task-btn-group{
        margin-bottom: 5px;
    }
    .layui-btn-pass, .layui-btn-back, .layui-btn-detail {
        height: 24px;
        background-color: transparent;
        outline: none;
        border: none;
    }
    .layui-btn-detail{
        width: 22px;
        background: url('/dist/style/res/about/detail.png') no-repeat center center;
    }
    .layui-btn-pass{
        width: 23px;
        background: url('/dist/style/res/about/pass.png') no-repeat center center;
    }
    .layui-btn-back{
        width: 24px;
        background: url('/dist/style/res/about/back.png') no-repeat center center;
    }
    .form-tab-content .layui-table-cell{
        height: 27px;
        line-height: 27px;
        margin: 0 auto;
        overflow: auto;
    }
    .layui-table-view .layui-table{
        width:100%;
    }
    .layui-table-box .layui-table[lay-even] tbody tr.lineactive{
        background-color: #FDE7A3;
    }
    .btn-colla{
        height: 30px;
        line-height: 30px;
        border: none;
        background-color: #F6F7F8;
    }
    .btn-colla .layui-icon{
        right: 7px;
    }
    #usermemo{
        overflow: hidden;
    }
    #usermemo .layui-form-label{
        width: auto;
        padding:  9px 10px;
    }
    .layui-layer-btn .layui-layer-btn0{
        background-color: #2669B1;
        border-color: #2669B1;
    }
    .kqform-content {
        overflow: auto;
    }
    .kq-info-title {
        display: inline-block;
        height: 30px;
        line-height: 30px;
        margin-right: 30px;
    }
    .left-card .no-data-tips{
        margin-top: 70px;
    }
    .task-ul .no-data-tips{
        margin-top: 100px;
    }
    .layui-tab-content .layui-form-select{
        width: 250px;
        margin: auto;
    }
    .height-auto{
        height: 385px;
    }
    .height-max{
        height: 825px;
    } 
    .btn-request,
    .btn-feedback,
    .btn-requestProcess{ 
        border: 1px solid #1C74D4;
        color: #1C74D4;
    }

    .download-fileBox{
        position: relative;
    }
    .fileAllBox{
        position: absolute;
        left: 14%;
        top: 26px;
        background: #000;
        display: none;
        padding: 6px;
        z-index: 9999;
    }
    .fileAllBox p{
        color: white;
        font-size: 14px;
    }
    .showEntuserCircle{
        display: inline-block;
        width: 10px;
        height: 10px;
        position: absolute;
        background: #ef5757;
        border-radius: 50%;
        top: 35%;
        right: 6px;
        cursor: pointer;
    }
</style>
<div class="custom-taskReview-page">
    <div class="layui-fluid top-part">
        <div class="layui-row layui-col-space10">
            <div class="layui-col-md12">
                <div class="layui-card left-card">
                    <div class="layui-card-header">
                        <img src="../../../../dist/style/res/formFill/tem-task.png" class="card-header-icon"/>
                        <span class="card-header-title">请示中的任务列表</span>
                    </div>
                    <div class="layui-card-body task-to-reviewBox">
                        <table class="layui-hide task-list" id="task-to-review" lay-filter="task-to-review"></table>
                    </div>
                </div>
            </div>
            <div class="layui-col-md3 layui-hide">
                <div class="layui-card right-card">
                    <div class="layui-card-header undo-task">
                        <img src="../../../../dist/style/res/formFill/tem-task.png" class="card-header-icon"/>
                        <span class="card-header-title">表单信息</span>
                    </div>
                    <div class="task-ul">
                        <ul class="scroll"></ul>
                    </div>
                </div>
            </div>
      </div>
    </div>
    <div class="layui-fluid">
        <div class="layui-col-md12">
            <div class="layui-card select-form-box" style="margin: 0;">
                <div class="layui-card-header clearfix select-form-header">
                <div class="card-header-left left">
                    <img src="../../../../dist/style/res/formFill/tem-task.png" class="card-header-icon"/>
                    <div class="layui-inline custom-card-header">
                        <span class="card-header-title">填报列表</span>
                        <span class="layui-title-mid layui-hide">-</span>
                        <span class="card-header-subtitle"></span>
                    </div>
                </div>
                <div class="card-header-right right card-header-kq hide">
                    <div class="kq-info-title">
                        <span>填报单位：</span><span class="c-unit"></span>&nbsp;&nbsp;
                        <span>考勤日期：</span><span class="c-startDate"></span>~<span class="c-endDate"></span>
                    </div>
                    <button class="layui-btn layui-btn-primary btn-colla E-btn" data-target="colla">
                        <i class="layui-icon layui-icon-up"></i>
                    </button>
                </div>
                </div>
                <div class="layui-tab layui-tab-card otherForm-content layui-form" lay-filter='tabSwitch'>
                    <ul class="layui-tab-title form-tab-title"></ul>
                    <div class="layui-tab-content form-tab-content"></div>
                </div>
                <div id="audit-form-task-kqform" class="kqform kqform-content"></div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="modify-form">
    <button class="addLine" lay-event="addLine"></button>
    <button class="delLine" lay-event="delLine"></button>
</script>
<!-- 任务列表状态栏 -->
<script type="text/html" id="state">
    {{#
		var getStatusColor = function() {
			var mapColors = {
                '00': 'layui-bk-green',
                '20': 'layui-bk-gray',
                '25': 'layui-bk-orange',
                '30': 'layui-bk-green',
                '40': 'layui-bk-orange',
                '90': 'layui-bk-gray',
                '99': 'layui-bk-gray'
			};
			return mapColors[d.state] || '';
        };
        var disPlayTxt=d.entuser_name?'inline-block':'none' 
	}}
    <!-- <span class="custom-badge {{getStatusColor()}}">{{d.statename}}</span>	 -->
    <div class="custom-badge {{getStatusColor()}}">{{d.statename}}<span  class="showEntuserCircle" style="display:{{disPlayTxt}}" lay-tips='委托人：{{d.entuser_name}}'></span></div>		
</script>
<!-- 任务状态模板 -->
<script type="text/html" id="taskState">
    {{#
		var getStatusColor = function() {
			var mapColors = {
                '00': 'layui-bk-green',
                '20': 'layui-bk-gray',
                '25': 'layui-bk-orange',
                '30': 'layui-bk-green',
                '40': 'layui-bk-orange',
                '90': 'layui-bk-gray',
                '99': 'layui-bk-gray'
			};
			return mapColors[d.state] || '';
		};
	}}
	<span class="custom-badge {{getStatusColor()}}">{{d.statename}}</span>	
</script>

<!-- 工具栏模板 -->
<script type="text/html" id="examine">
    <button class="layui-btn layui-btn-primary layui-btn-xs layui-btn-detail layui-hide" lay-event="detail" lay-tips="下发单位"></button>
    <button class="layui-btn layui-btn-primary layui-btn-xs layui-btn-pass" lay-event="pass" lay-tips="通过"></button>
    <button class="layui-btn layui-btn-primary layui-btn-xs layui-btn-back" lay-event="back" lay-tips="退回"></button>
</script>

<!-- 待办任务 -->
<script type="text/html" id="auditTask">
    {{# if(d && d.length > 0){ }}
        <li class="undotask-header">
            <span class="title-num">序号</span>
            <span class="title-content">任务名称</span>
            <span class="title-time">填报结束时间</span>
        </li>
        {{# layui.each(d, function(index, item){ }}
            <li class="clearfix E-btn" data-jump={{item.connection}} data-target="jump">
                <div class="task-content-box">
                    <span class="task-num">{{index+1}}</span>
                    <span class="task-content"  lay-tips={{item.taskname}}>{{item.statename}}-{{item.taskname}}</span>
                </div>
                <div class="task-time">{{item.endtime}}</div>
            </li>
        {{# }); }}
    {{# }else{ }}
        <div class="no-data-tips">
            <img src="/src/style/res/about/empty.png">
            <p style="color:#DBDBDB;">暂无数据</p>
        </div>
    {{# } }}
</script>
<!-- 任务列表附件栏 -->
<script id="download" type="text/html">
    {{# if(!!d.fileNames && d.fileNames.length && d.fileNames.length > 0){     }}
        {{#   layui.each(d.fileNames, function(index, file){ }}
            <a class="download-file" lay-event="download" data-url={{file.url}} lay-tips='{{file.filename}}'>{{file.filename}}</a>
        {{# }); }}    
    {{# } }}
</script>
<!--  -->
<!-- 请示中的任务列表操作栏 -->
<script type="text/html" id="test-table-thead-barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs btn-detail layui-hide" lay-event="detail"><span>下发单位</span></a>
    {{# if(d.writetype != '3'){ }} 
        <a class="layui-btn layui-btn-primary layui-btn-xs btn-feedback"  lay-event="feedback">
            反馈
        </a>
        <a class="layui-btn layui-btn-primary layui-btn-xs btn-request" lay-event="request">
            请示
        </a>
        <a class="layui-btn layui-btn-primary layui-btn-xs btn-requestProcess" lay-event="requestProcess">
            请示流程
        </a>
    {{# } }}
</script>
<script>
    var radioChooseUser={}; 
layui.use(['admin', 'table', 'element', 'tools', 'laytpl', 'form', 'laypage'], function(){
    var $ = layui.$,
        layer = layui.layer,
        element = layui.element,
        table = layui.table,
        admin = layui.admin,
        tools = layui.tools,
        view = layui.view,
        laytpl = layui.laytpl,
        router = layui.router(),
        search = router.search,
        form = layui.form,
        laypage = layui.laypage;


    var delRows = [], //删除行数据
        colName = [], //列名
        layout = ['.layui-table th', '.layui-table td', '.task-ul>ul'];
    window.tabIndex = 0; //选项卡下标 默认为0
    window.tableId = 'test-table-cellEdit1'; //选项卡表单id

    getTaskReview();

    //查询常驻任务
    function viewCz(id, checking) {
        var url = checking !== '1' ? 'myapi/DC/api/rest/web/custom/GetTaskMsgsById' : 'myapi/DC/api/rest/web/custom/CheckTaskDataSelect?model=updateSelect';
        var args = {
            id: id
        },
        cArgs = {
            taskid: id
        };
        admin.req({
            url: url,
            data: checking !== '1' ? args : cArgs,
            success: function(res){
                var data = checking !== '1' ? res.data : res.data.data;
                clickForTr(data, data.isChecking);
            }
        });
    }

    //查询临时任务
    function viewLs(id) {
        admin.req({
            url: 'myapi/DC/api/rest/web/custom/GetTaskMsgsById',
            data: {
                id: id
            },
            success: function(res){
                if(res.retcode == '0'){
                    clickForTr(res.data, res.data.isChecking);
                }
            }
        })
    }

    //请示填报的任务列表
    function getTaskReview(){
        table.render({
            elem: '#task-to-review'
            ,height: 385
            ,url: 'myapi/DC/api/rest/web/custom/GetAskTask'
            ,where: { 
                access_token: layui.data('layuiAdmin').access_token
            }
            ,text: {
                none: '<div class="no-data-tips"><img src="/src/style/res/about/empty.png"><p style="color:#DBDBDB;">暂无数据</p></div>'
            }
            ,request: {
                limitName: 'count'
            }
            ,parseData: function(res){ 
                return {
                    "code": res.retcode, 
                    "msg": res.retmsg, 
                    "count": res.data.totalNumber, 
                    "data": res.data.data 
                };
            }
            ,cellMinWidth: 80 
            ,page: {
                groups: 1, 
                limit: 10,
                next:'<i class="layui-icon">&#xe602;</i>',
                prev:'<i class="layui-icon">&#xe603;</i>',
                first: '<i class="layui-icon">&#xe65a;</i>',
                last: '<i class="layui-icon">&#xe65b;</i>',
                layout: ['refresh', 'first', 'prev', 'skip', 'count', 'allPage', 'next', 'last'],
                extend:{
                    first: true,
                    spr: false,
                    pagecount: true
                }
            }
            ,cols: [ [
            { type: 'numbers', title: '序号', width: 44 },
                { title: '任务状态', toolbar: '#state', width: 105 },
                {
                    field:'taskname',
                    title: '任务名称', 
                    minWidth: 300,
                    templet: function(d){
                        return '<span lay-tips="'+ d.taskname +'">'+ d.taskname +'</span>'
                    }
                },{field:'starttime', title: '开始时间',  minWidth: 200, 
                    templet: function(d){
                        return '<span lay-tips="'+ d.starttime +'">'+ d.starttime +'</span>'
                    }
                }
                ,{field:'endtime', title: '结束时间', minWidth: 200, 
                    templet: function(d){
                        return '<span lay-tips="'+ d.endtime +'">'+ d.endtime +'</span>'
                    }
                }
                ,{
                    field:'memo', 
                    title: '填报要求',
                    minWidth: 200,
                    templet: function(d){
                        return '<span lay-tips="'+ d.memo +'">'+ d.memo +'</span>'
                    }
                }
                ,{ field: 'username', title: '发布人', width: 150, templet: function(d){
                        return '<span lay-tips="'+ d.username +'">'+ d.username +'</span>'
                    } 
                }
                ,{ field: 'deptname', title: '任务发布单位', width: 150,
                    templet: function(d){
                        return '<span lay-tips="'+ d.deptname +'">'+ d.deptname +'</span>'
                    }
                }
                ,{field: 'createtime', title: '发布时间',  minWidth: 200, 
                    templet: function(d){
                        return '<span lay-tips="'+ d.createtime +'">'+ d.createtime +'</span>'
                    }
                }
               
                ,{ title: '任务附件',  
                    field: 'fileNames',
                    //toolbar: '#download',
                    minWidth: 200,
                    templet: function(d){  
                        var newDownLoadBox="";
                        var fileNames=d.fileNames;
                        if(fileNames&&fileNames.length>0){
                            for(var i=0;i<fileNames.length;i++){
                                newDownLoadBox+='<p class="download-file" lay-event="download" data-url='+fileNames[i].url+' >'+fileNames[i].filename+'</p>'
                            }   
                            return ' <div class="download-fileBox">'+
                                    '<a class="download-file downLoadFileBtn" >下载附件</a>'+  
                                    '<div class="fileAllBox">'+
                                        newDownLoadBox+
                                    '</div>'+
                                    '</div>'
                            
                        }else{
                            return '' 
                        }
                        // <a class="download-file" lay-event="download" data-url={{file.url}} lay-tips='{{file.filename}}'>{{file.filename}}</a>
                        }

                } 
                ,{
                    field:'askmemo', 
                    title: '反馈信息',
                    minWidth: 260,
                    templet: function(d){
                        return '<span lay-tips="'+ d.askmemo +'">'+ d.askmemo +'</span>'
                    }
                }
                ,{ field: 'opearte', title:'任务操作', toolbar: '#test-table-thead-barDemo', width: 260 }
            ]
            ]
            ,even: true 
            ,done: function(res, curr, count){
                $(".download-fileBox").parent(".layui-table-cell").css({"overflow":"visible"})
                    $(".download-fileBox").on("mouseover",function(){  
                        $(this).find(".fileAllBox").show();  
                    })
                    $(".download-fileBox").on("mouseout",function(){ 
                        $(this).find(".fileAllBox").hide(); 
                    })
                if(res.data && res.data.length > 0){
                    var isChecking = res.data[0].checking;
                    //clickForTr(res.data[0], isChecking);
                    window.taskId = res.data[0].id;
                    tools.clickToTask(res.data, router, 'task-to-review'); 
                }else{
                    //清除考勤任务
                    $('#audit-form-task-kqform').empty();
                    $('.kq-info-title .c-unit').text('');
                    $('.kq-info-title .c-startDate').text('');
                    $('.kq-info-title .c-endDate').text('');
                    $('.card-header-kq').addClass('hide');
                    $('.kqform-content').hide();
                    //清理普通任务
                    $('.form-tab-title').empty();
                    $('#'+window.tableId).next().find('.layui-table-box').empty();
                    $('.form-tab-content').empty().html('<div class="no-data-tips"><img src="/src/style/res/about/empty.png"><p style="color:#DBDBDB;">暂无数据</p></div>');
                }
                tools.setFont(layout);
            }
        }); 
    }

    //填报考勤任务表单详情列表加载
    function getKQTaskForm(taskid) {
        admin.req({
            type: 'get',
            url: 'myapi/DC/api/rest/web/custom/TaskAuditForms',
            data: {
                taskid: taskid,
                checking: '1',
            },
            success: function(res) {
                var dates = res.data.users.length > 0 ? res.data.users[0].users_time[0].users_time_day : [],
                    users = res.data.users;
                $('.kq-info-title .c-startDate').text(res.data.starttime ||' 暂无');
                $('.kq-info-title .c-endDate').text(res.data.endtime ||' 暂无');
                view('audit-form-task-kqform').render('./audit/components/kqTaskReview', {
                    dates: dates, 
                    users: users,
                    basic: {
                        dept_code: res.data.dept_code,
                        dept_name: res.data.dept_name,
                        dept_id: res.data.dept_id,
                        taskid: taskid
                    }
                });
                tools.setFont(layout);
            }
        });
    }

    //加载填报表单
    function getTaskForm(taskid){
        admin.req({
            url: 'myapi/DC/api/rest/web/custom/TaskAuditForms',
            data: {
                taskid: taskid,
                access_token: layui.data('layuiAdmin').access_token
            },
            success: function(res) {
                if(res.retcode == '0' && res.data && res.data.length > 0){            
                    $('#'+window.tableId).empty();
                    var titleHtml = '', 
                        tableHtml = '', 
                        data = res.data;

                    for(var i = 0; i < data.length; i++){
                        if(i == window.tabIndex){ 
                            titleHtml +=  '<li class="layui-this">'+data[i].formname+'</li>';
                            tableHtml += '<div class="layui-tab-item layui-show">'+
                                            '<table id="test-table-cellEdit'+(i+1)+'" lay-filter="test-table-cellEdit'+(i+1)+'"></table>'+
                                         '</div>';
                        }
                        else{ 
                            titleHtml += ' <li>'+data[i].formname+'</li>';
                            tableHtml += '<div class="layui-tab-item">'+
                                            '<table id="test-table-cellEdit'+(i+1)+'" lay-filter="test-table-cellEdit'+(i+1)+'"></table>'+
                                         '</div>';
                        }
                    }
                    $('.form-tab-title').empty().html(titleHtml);
                    $('.form-tab-content').empty().html(tableHtml);
                    var data = data[window.tabIndex],
                        cols = data.cols,
                        supContent = data.supcontent;
                        grid = data.data.grid;
                    colData = grid && grid.length > 0 ? grid : tools.getGridData(cols);
                    tools.addOtherCols(cols, false);

                    var options = {
                        elem: '#'+ window.tableId,
                        cols: cols,
                        skin: 'nob',
                        even: true,
                        data: colData,
                        done: function(res, curr, count){
                            tools.loadSelectFunction(supContent);
                            form.render('select', 'tabSwitch');
                            tools.setFont(layout);
                        }
                    };
                    table.render(options);
                }
            }
        })
    }


    //待办任务
    function getUndoTask(){
        var appid = layui.data('userdata').appId;
        admin.req({
            url: 'myapi/DC/api/rest/web/custom/GetTasksByUserApp',
            data: {
                app_id: appid,
            },
            success: function(res){
                if(res.retcode == '0'){
                    var data = res.data.auditTask.concat(res.data.writeTask),
                        getTpl = auditTask.innerHTML,
                        view = document.querySelector('.task-ul ul');
                    laytpl(getTpl).render(data, function(html){
                        view.innerHTML = html;
                    })
                }
            }
        })
    }

    //获取表头数据
    function getUTable(formhtml, type){
        var div = document.createElement('div');
        div.innerHTML = formhtml;
        var allTh = div.querySelectorAll('table th'),
            allTr = div.querySelectorAll('table tr'),
            colhead = [],
            colbody = [];

        layui.each(allTh, function(index, item){
            var fieldenglish = item.getAttribute('id'),
                fieldname = item.innerText;
            colhead.push({
                field: fieldenglish,
                title: fieldname,
                minWidth: 230
            })
        });

        layui.each(allTr, function(index2, eachTr){
            var rowTd = eachTr.querySelectorAll('td');
            layui.each(rowTd, function(index3, eachTd){
                if(eachTd.innerText != ''){ //表格存在数据时
                    var obj = new Object();
                    layui.each(colhead, function(index4, content){
                        var field = content.field;
                        obj[field] = rowTd[index4].innerText; 
                    })
                    colbody.push(obj);
                    colbody = deteleObject(colbody);
                }
            })
        })
        if(colbody.length  == 0 || colbody.length < 5){ //表格没有数据时，默认添加5个空行
            var len = 5 - colbody.length;
            for(var i = 0; i < len; i++){ 
                var obj = new Object();
                layui.each(colhead, function(index5, item5){
                    var field = item5.field;
                    obj[field] = ''; 
                })
                colbody.push(obj);
            }
        }
        if(type == 'thead'){
            return colhead
        }else{
            return colbody
        }
    }

    //不同任务类型做不同的元素切换
    function pickTypeShow(type) {
        if(type === 'other') {
            $('.otherForm-content').show();
            $('.kqform-content').hide();
            $('.card-header-kq').hide();
        }else if(type === 'kqform') {
            $('.otherForm-content').hide();
            $('.kqform-content').show();
            $('.card-header-kq').show();
        }
    }

    //监听Tab切换
    element.on('tab(tabSwitch)', function(data){
        var index = data.index + 1;
        window.tableId = 'test-table-cellEdit'+index; //表格ID
        window.tabIndex = data.index; //选项卡下标
        getTaskForm(window.taskId);
    })

    //任务列表 => 监听行点击事件
    table.on('row(task-to-review)', function(obj){

        $('[lay-id="task-to-review"]').find(obj.tr.selector).addClass('lineactive');
        $('[lay-id="task-to-review"]').find(obj.tr.selector).siblings().removeClass('lineactive');
        window.taskId = obj.data.id;
        window.tabIndex = 0;
        window.tableId = 'test-table-cellEdit1'; 
        tools.setNavText();
        tools.setTaskFormTitle(obj.data.taskname);
        clickForTr(obj.data, obj.data.checking);
    });

    //行点击事件
    function clickForTr(data,checking) {
        if(checking === '1') {
            getKQTaskForm(data.id);
            $('.kq-info-title .c-unit').text(data.deptname ||' 暂无');
            pickTypeShow('kqform');
        }else {
            getTaskForm(data.id);
            pickTypeShow('other');
        }
    }

    //待办任务点击事件
    $('.task-ul').delegate('li.E-btn', 'click', function(){
        var toJump = $(this).attr('data-jump');
        location.hash = search.redirect ? decodeURIComponent(search.redirect) : '/'+toJump;
    })

    //点击事件
    $('.E-btn').click(function(){
        var target = $(this).data('target');
        if(target == 'colla'){
            var tbHeight = 0,
                flag = $(this).find('.layui-icon').hasClass('layui-icon-up');
            $('.left-card').slideToggle();
            $('.right-card').slideToggle();
            $(this).find('i').toggleClass("layui-icon-up layui-icon-down");
            $(this).parents('.select-form-box').toggleClass('height-auto height-max');
            tbHeight = flag ? 700 : 250;
            table.reload(window.tableId, {
                height: tbHeight
            });
        }
    })

    //监听工具栏按钮
    table.on('tool(task-to-review)', function(obj){
        layui.stope(obj.ev);
        var event = obj.event,
            data = obj.data,
            thisModel = null,
            memoTitle = '反馈'; 
        if(event == 'feedback'){//反馈 
            var clickfeedbackFlag=false;
            layer.open({
                id: 'usermemo',
                type: 1,
                title: '<i class="formFill-icon"></i><span style="color:#FFF;">'+memoTitle+'</span>',
                area: ['300px', '250px'],
                offset: 'auto',
                shadeClose: true,
                resize: false,
                success: function(lay, index){
                    view(this.id).render('./audit/components/userfeedback', {
                        showReview: false
                    });
                },
                btn: ['确定', '取消'],
                btnAlign: 'c',
                yes: function(index, layero){
                    var memoval = $('#usermemo .layui-textarea').val();
                        if(!clickfeedbackFlag){ 
                            clickfeedbackFlag=true;
                            if(memoval.trim()!=""){ 
                                    admin.req({
                                        url: 'myapi/DC/api/rest/web/custom/AskFeedback',
                                        type: 'post',
                                        data:{ 
                                            writeaskid:data.writeaskid,
                                            model: "back",
                                            askmemo: memoval
                                        },
                                        success: function(res){  
                                            if(res.data.retcode == '0'){
                                            //    thisModel == 'pass' ? layer.msg('通过成功', {time: 1000}) : layer.msg('退回成功', {time: 1000});
                                                layer.msg(res.data.retmsg,{time:1000},function(){
                                                    layer.close(index);
                                                    clickfeedbackFlag=false;
                                                    getTaskReview();
                                                    // getUndoTask();
                                                })
                                            
                                            }else{
                                                clickfeedbackFlag=false;
                                                layer.msg(res.data.retmsg,{time:1000})
                                            }
                                        }
                                    }) 
                            }else{
                                clickfeedbackFlag=false;
                                layer.msg("反馈内容不能为空！",{time:1000})
                            }
                        }
                        
                },
                btn2: function(index, layero){}
            })
        }else{
            var reviewUrl = '',area=['570px', '650px'],title;
            if(event === 'request') {//请示
                reviewUrl = './task/temporary/choosePerson';
                area=['570px', '650px'];
                title="请示"
            }else if(event === 'requestProcess') {//请示流程
                reviewUrl = './task/temporary/showProcessChart';
                area=['650px', '400px'],
                title="请示流程"
            } 
            layer.open({
                    id: 'temporary-reviewHtml',
                    title: '<i class="formFill-icon"></i><span style="color:#FFF;">'+title+'</span>',
                    type: 1,
                    offset: '20px',
                    shadeClose: true,
                    area: area,
                    success: function(lay, index){
                        view(this.id).render(reviewUrl, {
                            writeid:obj.data.writeid,
                            taskname:obj.data.taskname
                        }).done(function() {
                            var clickSureFlag=false;
                            $(lay).on('click', '.T-confirm', function(){  
                                if(!clickSureFlag){ 
                                        var  askmemoTxt=$(lay).find('#requestDeContent').val();
                                        clickSureFlag=true;
                                        if(radioChooseUser.user_code&&askmemoTxt.trim()!=""){
                                            admin.req({
                                                    url: 'myapi/DC/api/rest/web/custom/AskFeedback',
                                                    type: 'post',
                                                    data: { 
                                                        writeaskid: obj.data.writeaskid, 
                                                        model:"askfor",
                                                        user_code:radioChooseUser.user_code,
                                                        user_name:radioChooseUser.user_name,
                                                        askmemo:askmemoTxt,
                                                        access_token: layui.data('layuiAdmin').access_token
                                                    },
                                                    success: function(res){
                                                        if(res.data.retcode == 0){ 
                                                            radioChooseUser={}; 
                                                             clickSureFlag=true;
                                                            layer.msg(res.data.retmsg,{time:1000},function(){  
                                                                getTaskReview();
                                                            layer.closeAll(); 
                                                            })
                                                        }else{
                                                            clickSureFlag=false;
                                                            layer.msg(res.data.retmsg,{time:1000})
                                                        }
                                                    },
                                                    error:function(err){
                                                        console.log('err', err)
                                                    }
                                                })
                                        }else{
                                            if(!radioChooseUser.user_name){
                                                clickSureFlag=false;
                                                layer.msg("请选择人员！",{time:1000})
                                            }else{
                                                clickSureFlag=false;
                                                layer.msg("请输入请示内容",{time:1000}) 
                                            }
                                        }  
                                        
                                } 
                                
                            }) 
                        });
                    }
                })

        }
        
        
        
    })

    //去除重复对象
    function deteleObject(obj) {
        var uniques = [];
        var stringify = {};
        for (var i = 0; i < obj.length; i++) {
            var keys = [];
            for(var key in obj[i]) {
                keys.push(key);
            }
            //var keys = Object.keys(obj[i]);
            keys.sort(function(a, b) {
                return (Number(a) - Number(b));
            });
            var str = '';
            for (var j = 0; j < keys.length; j++) {
                str += JSON.stringify(keys[j]);
                str += JSON.stringify(obj[i][keys[j]]);
            }
            if (!stringify.hasOwnProperty(str)) {
                uniques.push(obj[i]);
                stringify[str] = true;
            }
        }
        uniques = uniques;
        return uniques;
    }

})
</script>